package com.annotation.importBean.beanDefinitionRegistrar;

import com.annotation.importBean.RainBow;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * @author: qiuli
 * @date: 2022/1/7 18:15
 * @description:
 */


public class MyImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {
    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        //判断IOC容器里面是否含有这两个组件
        boolean definition = registry.containsBeanDefinition("com.annotation.importBean.Book");
        boolean definition2 = registry.containsBeanDefinition("com.annotation.importBean.Color");
        //如果有的话，我就把RainBow的bean的实例给注册到IOC容器中
        //指定bean的定义信息，参数里面指定要注册的bean的类型：RainBow.class
        RootBeanDefinition rootBeanDefinition = new RootBeanDefinition(RainBow.class);
        //注册一个bean，并且指定bean名
        registry.registerBeanDefinition("rainBow", rootBeanDefinition );
    }
}
